package com.bupt.fmmall.controller;

import com.bupt.fmmall.entity.Complaint;
import com.bupt.fmmall.entity.Customer;
import com.bupt.fmmall.service.*;
import com.bupt.fmmall.vo.ResultVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@ResponseBody
@RequestMapping("/customer")
@CrossOrigin
public class CustomerController {
    @Resource
    CustomerService customerService;
    @Resource
    ShoppingCartService shoppingCartService;
    @Resource
    OrderService orderService;
    @Resource
    ComplaintService complaintService;
    @Resource
    ReplyService replyService;

    @RequestMapping("/register")
    public int customerRegister(Customer customer){
        return customerService.registerCustomer(customer);
    }

    @RequestMapping("/login")
    public ResultVO customerLogin(String customerUserName, String customerPassword){
        return customerService.loginCustomer(customerUserName,customerPassword);
    }

    @RequestMapping("/cart/list")
    public ResultVO customerCartList(String customerUserName){
        return  shoppingCartService.findAllCartByUserId(customerUserName);
    }

    @RequestMapping("/cart/update")
    public ResultVO customerCartUpdate(Integer itemId,String customeruserName,Integer itemNumber){
        return shoppingCartService.set_ShoppingCartId_number(itemId,customeruserName,itemNumber);
    }

    @RequestMapping("/cart/delete")
    public ResultVO customerCartDelete(Integer itemId,String customeruserName){
        return shoppingCartService.delete_CartItem(itemId,customeruserName);
    }

    @RequestMapping("/index")
    public ResultVO customerIndexOrder(String customeruserName,Integer orderStatusId){
        return orderService.CusViewOrderStates(customeruserName,orderStatusId);
    }

    @RequestMapping("/index/getinfo")
    public ResultVO customerIndexInfo(String customeruserName){
        return customerService.getCustomerInfoByUsername(customeruserName);
    }

    @RequestMapping("/changeselfinfo")
    public ResultVO customerIndexChangeInfo(Customer customer){
        return customerService.changeCusInfo(customer);
    }

    @RequestMapping("/reply/listcomplaint")
    public ResultVO customerReplyListcomplaint(String customeruserName){
        return complaintService.customerViewAllComplaints(customeruserName);
    }

    @RequestMapping("/reply/makecomplaint")
    public ResultVO customerMakeComplaint(Complaint complaint){
        return  complaintService.customerComplaint(complaint);
    }

    @RequestMapping("/reply/deletecomplaint")
    public ResultVO customerDeleteComplaint(int complaintId){
        return  complaintService.customerWithdrawComplaint(complaintId);
    }

    @RequestMapping("reply/viewreply")
    public ResultVO customerViewReplt(int complaintId){
        return  replyService.customerViewReply(complaintId);
    }
}
